import request from "@/utils/request";
import { AxiosPromise } from "axios";
import qs from "qs";
import {
  BillEntityForm,
  BillEntityVO,
  BillEntityPageVO,
  BillEntityQuery,
  BillEntityGroupQuery,
  BillEntityGroupByDateVO,
} from "./types";

/**
 * 获取账单实体分页列表
 *
 * @param queryParams
 */
export function getBillEntityPage(
  queryParams: BillEntityQuery
): AxiosPromise<PageResult<BillEntityPageVO[]>> {
  return request({
    url:
      "/api/v1/billEntities/page?" +
      qs.stringify(queryParams, { arrayFormat: "repeat" }),
    method: "get",
  });
}

/**
 * 获取账单实体表单详情
 *
 * @param billEntityId
 */
export function getBillEntityForm(
  billEntityId: number
): AxiosPromise<BillEntityForm> {
  return request({
    url: "/api/v1/billEntities/" + billEntityId + "/form",
    method: "get",
  });
}

/**
 * 添加账单实体
 *
 * @param data
 */
export function addBillEntity(data: any) {
  return request({
    url: "/api/v1/billEntities",
    method: "post",
    data: data,
  });
}

/**
 * 修改账单实体
 *
 * @param id
 * @param data
 */
export function updateBillEntity(id: number, data: BillEntityForm) {
  return request({
    url: "/api/v1/billEntities/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 删除账单实体
 *
 * @param ids
 */
export function deleteBillEntities(ids: string) {
  return request({
    url: "/api/v1/billEntities/" + ids,
    method: "delete",
  });
}

/**
 * 部门树形表格
 *
 * @param queryParams
 */
export function listBillEntities(
  queryParams?: BillEntityQuery
): AxiosPromise<BillEntityVO[]> {
  return request({
    url:
      "/api/v1/billEntities?" +
      qs.stringify(queryParams, { arrayFormat: "repeat" }),
    method: "get",
  });
}

/**
 * 获取账单Entity下拉数据
 *
 * @param queryParams
 */
export function getBillEntityOptions(): AxiosPromise<[]> {
  return request({
    url: "/api/v1/billEntities/options",
    method: "get",
  });
}

export function getFromBillEntityByDate(
  queryParams?: BillEntityGroupQuery
): AxiosPromise<BillEntityGroupByDateVO[]> {
  return request({
    url:
      "/api/v1/billEntities/fromByDate?" +
      qs.stringify(queryParams, { arrayFormat: "repeat" }),
    method: "get",
  });
}

export function getToBillEntityByDate(
  queryParams?: BillEntityGroupQuery
): AxiosPromise<BillEntityGroupByDateVO[]> {
  return request({
    url:
      "/api/v1/billEntities/toByDate?" +
      qs.stringify(queryParams, { arrayFormat: "repeat" }),
    method: "get",
  });
}

export function getDiffBillEntityByDate(
  queryParams?: BillEntityGroupQuery
): AxiosPromise<BillEntityGroupByDateVO[]> {
  return request({
    url:
      "/api/v1/billEntities/diffByDate?" +
      qs.stringify(queryParams, { arrayFormat: "repeat" }),
    method: "get",
  });
}
